import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;


public class TickONOFF extends DefaultCellEditor implements TableCellRenderer {

	private JButton editButton;
	private JButton renderButton;
	private Boolean buttonValue = false;
	public TickONOFF(JCheckBox arg0) {
		// TODO Auto-generated constructor stub
		super(arg0);
        editButton = new JButton();
        renderButton = new JButton();
        editButton.setOpaque(true);
        editButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				fireEditingStopped();
			}
		});
	}

	public Object getCellEditorValue() {	
		return new Boolean(buttonValue);
	}
	
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		if (isSelected) {
			editButton.setForeground(table.getSelectionForeground());
			editButton.setBackground(table.getSelectionBackground());
		} else {
			editButton.setForeground(table.getForeground());
			editButton.setBackground(table.getBackground());
		}
		if (value != null) {
			if (value.equals(Boolean.TRUE)) {
				buttonValue = false;		
			} else {
				buttonValue = true;
			}
		} else {
			buttonValue = false;
		}
		return editButton;
	}
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
	boolean isSelected, boolean hasFocus, int row, int column) {
		// TODO Auto-generated method stub
		String label = "";
		if (value != null) {
			if (value.equals(Boolean.TRUE)) {
				label = "ON";
			} else {
				label = "OFF";
			}
		} else {
			label = "ON";
		}
		renderButton.setText(label);
		return renderButton;
	}
	
	public boolean stopCellEditing() {
		return super.stopCellEditing();
	}

	protected void fireEditingStopped() {
		super.fireEditingStopped();
	}

}
